<template>
    <div>

    </div>
</template>

<script setup lang="ts">
/**
 * 键入函数PromiseAll，它接受 PromiseLike 对象数组，返回值应为Promise<T>，其中T是解析的结果数组。
 */

 type MyAwaited<T> = T extends Promise<infer X> ? X : T;

declare function PromiseAll<T>(values: T): Promise<{
  [P in keyof T]: MyAwaited<T[P]>;
}>;

const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise<string>((resolve, reject) => {
  setTimeout(resolve, 100, 'foo');
});


// Promise<readonly [1, 2, 3]>
const promiseAllTest1 = PromiseAll([1, 2, 3] as const);
// Promise<readonly [1, 2, number]>
const promiseAllTest2 = PromiseAll([1, 2, Promise.resolve(3)] as const);
// Promise<number []>
const promiseAllTest3 = PromiseAll([1, 2, Promise.resolve(3)]);
// Promise<number []>
const promiseAllTest4 = PromiseAll<Array<number | Promise<number>>>([1, 2, 3]);



// expected to be `Promise<[number, 42, string]>`
const p = PromiseAll([promise1, promise2, promise3] as const);




</script>

<style scoped>

</style>